# -*-coding:utf-8-*-

from collections import Counter
from typing import Union, List
import numpy as np


def AAC(sequence: str,
        order: Union[str, None] = None) -> List:
    '''
    计算amino acid compositions
    :param sequence:string 序列
    :param order:Union[str,None] 默认"ACDEFGHIKLMNPQRSTVWY-"
    :return:List 21
    '''
    if order == None:
        order = "ACDEFGHIKLMNPQRSTVWY-"

    count = Counter(sequence)
    for key in count:
        count[key] = count[key] / len(sequence)
    encodings = []
    for aa in order:
        encodings.append(count[aa])
    return encodings


def one_AAC(data, windows=15):
    data = data
    length = len(data)
    data_X = np.zeros((length, 1, 21))
    data_Y = []
    for i in range(length):
        x = data[i].split(',')
        data_Y.append(int(x[4]))
        data_X[i][0] = AAC(x[5])
    data_Y = np.array(data_Y)
    return data_X, data_Y


if __name__ == '__main__':
    f_r_train = open('hit-40/totalsum.csv')
    train_data = f_r_train.readlines()
    result = one_AAC(train_data)
    print(result)
